package karileet.meeting.profile.receiver;

import karileet.meeting.profile.MeetingProfile;
import karileet.meeting.profile.ProfileConf;
import karileet.meeting.profile.fragment.ScheduleDialogFragment;
import karileet.meeting.profile.service.DisableProfileService;
import karileet.meeting.profile.service.EnableProfileService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class BootCompleteReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		ProfileConf state = new ProfileConf(context);
		Log.d(ProfileConf.APP, "Resuming services");
		if (state.isScheduleStartEnabled()) {
			Intent alarmIntent = new Intent(context, EnableProfileService.class);
			ScheduleDialogFragment.startService(state.getScheduleStart(), context, alarmIntent);
		}
		if (state.isScheduleStopEnabled()) {
			Intent alarmIntent = new Intent(context, DisableProfileService.class);
			ScheduleDialogFragment.startService(state.getScheduleStop(), context, alarmIntent);
		}
		Log.d(ProfileConf.APP, "Enabling profile when needed");
		if (state.isProfileEnabled()) {
			MeetingProfile mp = new MeetingProfile(context);
			mp.enable(false);
			mp.updateWidget();
		}
	}

}
